<template>
    <div>
        <!-- 表格 -->
        <el-table :data="getrole" border style="width: 100%">
            <el-table-column prop="id" label="角色编号" width="80">
            </el-table-column>
            <el-table-column prop="rolename" label="角色名称" width="120">
            </el-table-column>
            <el-table-column label="状态" width="300">
                <!-- <el-button type="success" plain size="mini">启用</el-button> -->
                <template slot-scope="item">
                    <div>
                        <el-button type="success" plain size="mini">{{ item.row.status == 1 ? "正常" : '禁用' }}</el-button>
                        
                    </div>
                </template>
            </el-table-column>
            <el-table-column label="操作" width="220">
                <template slot-scope="item">
                    <div>
                        <el-button type="primary" icon="el-icon-edit" plain size="mini"
                            @click="edit(item.row.id)">编辑</el-button>
                        <el-button type="danger" icon="el-icon-delete" plain size="mini"
                            @click="del(item.row.id)">删除</el-button>
                    </div>
                </template>
            </el-table-column>
        </el-table>
    </div>
</template>
<script>
import { roledelete } from '../../request/api'
import { mapActions, mapGetters } from 'vuex';
export default {
    data() {
        return {

        }
    },
    methods: {
        ...mapActions({
            getroleinfo: 'role/GetRoleInfo'
        }),
        // 编辑角色
        edit(id) {
            this.$emit('isShow', id)
        },
        // 删除角色
        del(id) {
            this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                roledelete({id})
                .then(res=>{
                    if(res.code == 200){
                        this.$message.success(res.msg)
                        this.$store.dispatch('role/GetRoleInfo')
                    }
                })
            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '已取消删除'
                });
            });
        }
    },
    mounted() {
        // console.log(this.$store);
        this.getroleinfo()
    },
    computed: {
        ...mapGetters({
            getrole: 'role/getRole'
        })
    },
    components: {}
}
</script>
<style scoped></style>